home *** CD-ROM | disk | FTP | other *** search
/ Web Page Construction Kit 3.0 / Web Page Construction Kit 3.0.iso / pc / source / 3rdparty / java / jdesnpro / data.1 / JDPLayout2.java < prev    next >
Encoding:
Text File  |  1996-07-29  |  12.5 KB  |  444 lines

  1. >XXX0444  Total lines for the build status message calculation
  2. //--------------------------------------------------------------------
  3. //                                                                    
  4. >001//  Module:       <JDPModule>                                       
  5. >002//  Description:  <Class Description>
  6. //                                                                    
  7. //--------------------------------------------------------------------
  8.  
  9. import java.awt.*;
  10. import java.applet.*;
  11. import java.util.StringTokenizer;
  12. import java.util.Vector;
  13. import java.util.Date;
  14.  
  15.  
  16. >003public class <JDPUserBill> extends JDPClassLayout {
  17.  
  18.     JDPUser user;
  19.     JDPJagg jaggSQL;
  20.     JDPTextGrid tableContents;
  21.     JDPWhereClause jdpWhereClause;
  22.  
  23.     String[] psortChoice;
  24.     String[] pdisplayChoice;
  25.     int itemIndex;
  26.     boolean insertRequested = false;
  27.     boolean deleteRequested = false;
  28.     String pfromWhereClause;
  29.     String[][] rowKey;
  30.     int keyCount;
  31.     int prevColumnCount;
  32. >119    int columnCount = <columnCount>;
  33.  
  34.     public void InitClass(JDPUser user, Panel targetPanel, String moduleParameter) {
  35.  
  36.         this.user = user;
  37.         //
  38.         //  Set JAGG settings for this class
  39.         //
  40.         jaggSQL = new JDPJagg(user.jaggPath);
  41.         jaggSQL.setNULL("space");
  42. >996        jaggSQL.setMRW("<maxRows>");
  43. >998        jaggSQL.setDSN("<datasource>");
  44. >999        jaggSQL.setCSTR("<connectstr>");
  45.  
  46.         setLayout(new BorderLayout());
  47.         setFont(user.plainFont);
  48.  
  49.         Panel mainPanel = new Panel();
  50.         mainPanel.setLayout(new BorderLayout());
  51.         Panel centerMainPanel = new Panel();
  52.         centerMainPanel.setLayout(new BorderLayout());
  53.  
  54.         //
  55.         //  Create a new instance of a Grid
  56.         //
  57.         tableContents = new JDPTextGrid(user);
  58.         mainPanel.add("Center",tableContents);
  59.         centerMainPanel.add("Center",mainPanel);
  60.         //
  61.         //  Add buttons to the bottom of the panel
  62.         //
  63.         if (moduleParameter.compareTo("Inquiry") == 0) {
  64.             String buttons[] = {""};
  65.             centerMainPanel.add("South",new JDPButtons(user, buttons, JDPButtons.HORIZONTAL));
  66.         } else {
  67. >015            String buttons[] = {<"   Apply   ","Reset","New","Copy","Remove">};
  68.             centerMainPanel.add("South",new JDPButtons(user, buttons, JDPButtons.HORIZONTAL));
  69.         }
  70.         
  71.         //
  72.         //  Define parameters for JDPWhereClause
  73.         //
  74. >016        String[] pchooseFrom = new String[<7>];
  75. >017        pchooseFrom[<0>] = "<Account Name>";
  76.  
  77. >018        String[] pactualchooseFrom = new String[<7>];
  78. >019        pactualchooseFrom[<0>] = "<username>";
  79.  
  80. >020        String[][] pmatchUsing = new String[<7>][<7>];
  81. >021        pmatchUsing[<0>][<0>] = "<Begins with>";
  82.  
  83. >022        String[][] pactualmatchUsing = new String[<7>][<7>];
  84. >023        pactualmatchUsing[<0>][<0>] = "< like >";
  85.  
  86. >024        boolean[] constantIsString = new boolean[<7>];
  87. >025        constantIsString[<0>] = <true>;
  88.  
  89. >026        int[] constantLength = new int[<7>];
  90. >027        constantLength[<0>] = <20>;
  91.  
  92.         //
  93.         //  Add JDPWhereClause search panel
  94.         //
  95.         if (pchooseFrom.length > 0) {
  96. >028            jdpWhereClause = new JDPWhereClause(user, "<UserBill>", false, "<pinitChoice>", pchooseFrom, pactualchooseFrom,
  97.                                                 pmatchUsing, pactualmatchUsing, null, null,
  98.                                                 constantLength, constantIsString);
  99.             centerMainPanel.add("North",jdpWhereClause);
  100.         }
  101.  
  102. >030        add("Center",new JDPChiselFramePanel(user,"<User Billing Details>",centerMainPanel,"North"));
  103.         loadGrid();
  104.  
  105.         // repaint the panel
  106.         targetPanel.add("Center",this);
  107.         targetPanel.paintAll(targetPanel.getGraphics());
  108.         //
  109.         //  Add the handle to this panel to the global vector so other panels can
  110.         //  access this one
  111.         //
  112.         user.gParm.addElement(this);
  113.     }
  114.  
  115.     //
  116.     //  Handle screen events
  117.     //
  118.     public boolean handleEvent(Event e) {
  119.  
  120.         switch (e.id) {
  121.         case Event.ACTION_EVENT:
  122.             if (e.target instanceof Button) {
  123.                 String choice = (String)e.arg;
  124.                 if (choice.trim().compareTo("Apply") == 0) {
  125.                     if (checkFields()) {
  126.                         checkRows();
  127.                     }
  128.                     return true;
  129.                 }
  130.                 if (choice.trim().compareTo("Reset") == 0) {
  131.                     if (insertRequested) {
  132.                         loadEmptyGrid();
  133.                     } else {
  134.                         loadGrid();
  135.                     }
  136.                     return true;
  137.                 }
  138.                 if (choice.trim().compareTo("Remove") == 0) {
  139.                     insertRequested = false;
  140.                     deleteRequested = true;
  141.                     checkRows();
  142.                     return true;
  143.                 }
  144.                 if (choice.trim().compareTo("Add") == 0) {
  145.                     if (!insertRequested) {
  146.                         insertRequested = true;
  147.                         loadEmptyGrid();
  148.                     }
  149.                     return true;
  150.                 }
  151.                 if (choice.trim().compareTo("Search") == 0) {
  152.                     insertRequested = false;
  153.                     newSearch();
  154.                     return true;
  155.                 }
  156.                 return false;
  157.             }
  158.             if (e.target instanceof Choice) {
  159.                 return true;
  160.             }
  161.             if (e.target instanceof TextField) {
  162.                 if ((jdpWhereClause != null) && (e.target.equals(jdpWhereClause.matchConstant))) {
  163.                     insertRequested = false;
  164.                     deleteRequested = false;
  165.                     newSearch();
  166.                     return true;
  167.                 }
  168.                 checkFields();
  169.                 return true;
  170.             }
  171.             return false;
  172.  
  173.         case Event.WINDOW_EXPOSE:
  174.             if (e.target instanceof JDPTabSelectTopPanel) {
  175.                 //
  176.                 //  This is where you place code to get executed when this panel is
  177.                 //  reactivated from the tab menu
  178.                 //
  179.                 return true;
  180.             }
  181.             return false;
  182.  
  183.         default:
  184.             return false;
  185.  
  186.         }
  187.     }
  188.  
  189.     //
  190.     //  Retrieve the handle to another panel so as to be able to interact with it
  191.     //
  192.     public void retrieveHandle() {
  193.  
  194.         for (int ix=0; ix<user.gParm.size(); ix++) {
  195.             //
  196.             //  Activate the next four lines of code to retrieve the handle to another 
  197.             //  Panel within your JDP system. Of course you should declare the variable 
  198.             //  at the top of this source instead of within this method so you can 
  199.             //  access it from all the methods within this class. You only need to 
  200.             //  substitute DemoClass with the name ouf your class. You should call this 
  201.             //  method from somewhere else in this class. To access a variable from 
  202.             //  your resulting class use:
  203.             //     if (DemoClassHandle != null) mynewvar = demoClassHandle.variable;
  204.             //
  205. //            if (user.gParm.elementAt(ix) instanceof DemoClass19) {
  206. //                DemoClass19 DemoClassHandle = (DemoClass19)user.gParm.elementAt(ix);
  207. //                return;
  208. //            }
  209.         }
  210.     }
  211.  
  212.     //
  213.     //  The search button was pressed so rerun the query with the new search criteria
  214.     //
  215.     public void newSearch() {
  216.  
  217.         loadGrid();
  218.     }
  219.  
  220.     //
  221.     //  The check each rows that has changed and issue an update to the database
  222.     //
  223.     public void checkRows() {
  224.  
  225.         int changedCount = 0;
  226.         int thisCount = 1;
  227.         
  228.         if (!deleteRequested) {
  229.             for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  230.                 if (tableContents.rowChanged[ix]) {
  231.                     changedCount++;
  232.                 }
  233.             }
  234.             for (int ix=0; ix<tableContents.rowChanged.length; ix++) {
  235.                 if (tableContents.rowChanged[ix]) {
  236.                     if (insertRequested) {
  237.                         user.mainmsg.setStatusMsg("Inserting row " + Integer.toString(thisCount++) + " of " + Integer.toString(changedCount) + "...", 0);
  238.                     } else {
  239.                         user.mainmsg.setStatusMsg("Updating row " + Integer.toString(thisCount++) + " of " + Integer.toString(changedCount) + "...", 0);
  240.                     }
  241.                     saveData(ix);
  242.                     tableContents.rowChanged[ix] = false;
  243.                 }
  244.             }
  245.             if ((insertRequested) && (changedCount > 0)) {
  246.                 loadEmptyGrid();
  247.             }
  248.         } else {
  249.             for (int ix=0; ix<tableContents.rowSelected.length; ix++) {
  250.                 if (tableContents.rowSelected[ix]) {
  251.                     changedCount++;
  252.                 }
  253.             }
  254.             if (changedCount == 0) {
  255.                 user.mainmsg.setStatusMsg("Select the row you wish to remove by clicking on the row number button.", 7);
  256.             } else {
  257.                 for (int ix=0; ix<tableContents.rowSelected.length; ix++) {
  258.                     if (tableContents.rowSelected[ix]) {
  259.                         user.mainmsg.setStatusMsg("Deleting row " + Integer.toString(thisCount++) + " of " + Integer.toString(changedCount) + "...", 0);
  260.                         saveData(ix);
  261.                         tableContents.rowChanged[ix] = false;
  262.                     }
  263.                 }
  264.                 newSearch();
  265.             }
  266.         }
  267.     }
  268.  
  269.     //
  270.     //  Save the selected item
  271.     //
  272.     public boolean saveData(int tableRow) {
  273.  
  274.         int recCount = 0;
  275.         Vector results = new Vector();
  276.         String sep = jaggSQL.getSEP();
  277.         String SQL = "";
  278.  
  279.         if (insertRequested) {
  280. >121            SQL = <INSERT INTO >;
  281.         } else {
  282.             if (deleteRequested) {
  283. >122                SQL = <DELETE FROM >;
  284.             } else {
  285. >123                SQL = <UPDATE >;
  286.             }
  287.         }
  288.  
  289.         recCount = jaggSQL.execSQL(SQL, results);
  290.  
  291.         if (user.DEBUG) System.out.println("saveData CNT: "+Integer.toString(recCount));
  292.  
  293.         if(recCount == -1) {
  294.             System.out.println("saveData SQL: "+SQL);
  295.             user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator.", 10);
  296.             return false;
  297.         }
  298.         if(recCount == 1) {
  299.             if (insertRequested) {
  300.                 user.mainmsg.setStatusMsg("Record successfully added.",3);
  301.             } else 
  302.             if (deleteRequested) {
  303.                 user.mainmsg.setStatusMsg("Record successfully removed.",3);
  304.             } else {
  305.                 user.mainmsg.setStatusMsg("Record successfully updated.",3);
  306.             }
  307.         } else {
  308.             user.mainmsg.setStatusMsg("SQL failed. Contact the System Administrator.", 10);
  309.         }
  310.         deleteRequested = false;
  311.         return true;
  312.  
  313.     }
  314.  
  315.     //
  316.     //  Load the grid with the specified parameters and selected data
  317.     //
  318.     public void loadGrid() {
  319.  
  320.         StringTokenizer stok;
  321.         int recCount = 0;
  322.         Vector results = new Vector();
  323.         String sep = jaggSQL.getSEP();
  324.         int actualRows = 0;
  325.         String row;
  326.  
  327.         Vector columns = new Vector();
  328.         Vector indexes = new Vector();
  329.  
  330. >100        String SQL = <SELECT>;
  331.  
  332.         user.mainmsg.setStatusMsg("Accessing database...", 0);
  333.  
  334.         recCount = jaggSQL.execSQL(SQL, results);
  335.  
  336.         if(recCount == -1) {
  337.             user.mainmsg.setStatusMsg("SQL error. Contact the System Administrator", 20);
  338.             System.out.println("loadGrid SQL: " + SQL);
  339.             return;
  340.         }
  341.  
  342.         //
  343.         //  Initialise result arrays
  344.         //
  345.         actualRows = jaggSQL.getRowCount();
  346.         tableContents.currentText = new String[columnCount][actualRows];
  347.         //
  348.         //  If we haven't already initialise the grid settings
  349.         //
  350.         if (columnCount != prevColumnCount) {
  351.             prevColumnCount = columnCount;
  352.             setGridSettings();
  353.         }
  354.         tableContents.cellChanged = null;
  355.         tableContents.rowChanged = null;
  356.         tableContents.columnSelected = null;
  357. >120        keyCount = <keycount>;
  358.         rowKey = new String[actualRows][keyCount];
  359.         
  360.         //
  361.         //  Load key array and grid array
  362.         //
  363.         for (int ix=0; ix<actualRows; ix++) {
  364.             row = (String)results.elementAt(ix);
  365.             if ((row != null) && (row.trim().compareTo("") != 0)) {
  366.                 stok = new StringTokenizer(row);
  367.                 for (int iy=0; iy<keyCount; iy++) {
  368.                     rowKey[ix][iy] = stok.nextToken(sep).trim();
  369.                 }
  370.                 for (int iy=0; iy<columnCount; iy++) {
  371.                     tableContents.currentText[iy][ix] = stok.nextToken(sep).trim();
  372.                 }
  373.             }
  374.         }
  375.  
  376.         tableContents.newTable();
  377.  
  378.         //
  379.         //  Clear status message
  380.         //
  381.         user.mainmsg.clearStatusMsg();
  382.     }
  383.  
  384.     //
  385.     //  Load the grid with the blank rows to allow data entry
  386.     //
  387.     public void loadEmptyGrid() {
  388.  
  389.         tableContents.currentText = new String[columnCount][50];
  390.         tableContents.cellChanged = null;
  391.         tableContents.rowChanged = null;
  392.         tableContents.columnSelected = null;
  393.         rowKey = new String[50][keyCount];
  394.         tableContents.newTable();
  395.     }
  396.  
  397.     //
  398.     //  Set up the parameters for this grid
  399.     //
  400.     public void setGridSettings() {
  401.  
  402.         tableContents.columnHeader = new String[columnCount];
  403.         tableContents.columnHeaderStyle = new int[columnCount];
  404.         tableContents.columnStyle = new int[columnCount];
  405.         tableContents.columnHeaderColor = new Color[columnCount];
  406.         tableContents.columnColor = new Color[columnCount];
  407.         tableContents.columnBGColor = new Color[columnCount];
  408.         tableContents.columnProtected = new boolean[columnCount];
  409.         tableContents.columnWidth = new int[columnCount];
  410.         tableContents.rightJustify = new boolean[columnCount];
  411.         tableContents.rowHeader = null;
  412.         tableContents.columnHeight = null;
  413.         for (int ix=0; ix<columnCount; ix++) {
  414.             tableContents.columnHeaderStyle[ix] = Font.BOLD;
  415.             tableContents.columnStyle[ix] = Font.PLAIN;
  416.             tableContents.columnHeaderColor[ix] = Color.black;
  417.             tableContents.columnColor[ix] = Color.black;
  418.             tableContents.columnBGColor[ix] = Color.white;
  419.             tableContents.columnStyle[ix] = Font.PLAIN;
  420.         }
  421. >101        tableContents.columnHeader[<ix>] = "<>";
  422. >102        tableContents.columnHeaderStyle[<ix>] = <>;
  423. >103        tableContents.columnStyle[<ix>] = <>;
  424. >104        tableContents.columnHeaderColor[<ix>] = user.u._cvtcolor("<>");
  425. >105        tableContents.columnColor[<ix>] = user.u._cvtcolor("<>");
  426. >106        tableContents.columnBGColor[<ix>] = user.u._cvtcolor("<>");
  427. >107        tableContents.columnProtected[<ix>] = <>;
  428. >108        tableContents.columnWidth[<ix>] = <>;
  429. >109        tableContents.rightJustify[<ix>] = <>;
  430.  
  431.     }
  432.  
  433.     //
  434.     //  Perform component validations
  435.     //
  436.     public boolean checkFields() {
  437.  
  438.         return true;
  439.  
  440.     }
  441.  
  442.  
  443. }
  444.